﻿using System;
using HarmonyLib;
using UnityEngine;

namespace zrgMod;

public partial class Plugin
{
    [HarmonyPostfix, HarmonyPatch(typeof(MapSeaCompent), nameof(MapSeaCompent.GetAddTimeNum))]
    public static void MapSeaCompent_GetAddTimeNum_Postfix(ref int __result)
    {
        // 玩家拥有天赋【航海士】：海上移动的时间消耗-35%（正常航行）
        if (PlayerEx.HasTianFu(690191))
        {
            __result = (int)Mathf.Ceil((Convert.ToSingle(__result) * 0.65f));
        }
    }

    [HarmonyPostfix, HarmonyPatch(typeof(UIMapSea), nameof(UIMapSea.CalcQuickMove))]
    public static void UIMapSea_CalcQuickMove_Postfix(ref SeaQuickMoveData __result)
    {
        // 玩家拥有天赋【航海士】：海上移动的时间消耗-35%和修理消耗-35%（快速移动）
        if (PlayerEx.HasTianFu(690191))
        {
            __result.CostDaySum = (int)Mathf.Ceil((Convert.ToSingle(__result.CostDaySum) * 0.65f));
            __result.XiuLiCostSum = (int)Mathf.Ceil((Convert.ToSingle(__result.XiuLiCostSum) * 0.65f));
        }
    }

    [HarmonyPrefix, HarmonyPatch(typeof(MapSeaCompent), nameof(MapSeaCompent.ReduceHP))]
    public static void MapSeaCompent_ReduceHP_Prefix(ref int realHp)
    {
        // 玩家拥有天赋【航海士】：海上无舟移动的生命损失-35%
        if (PlayerEx.HasTianFu(690191))
        {
            realHp = (int)Mathf.Ceil((Convert.ToSingle(realHp) * 0.65f));
        }
    }

    [HarmonyPrefix, HarmonyPatch(typeof(KBEngine.Avatar), nameof(KBEngine.Avatar.ReduceLingZhouNaiJiu))]
    public static void Avatar_ReduceLingZhouNaiJiu_Prefix(ref int num)
    {
        // 玩家拥有天赋【航海士】：灵舟的耐久消耗-35%
        if (PlayerEx.HasTianFu(690191))
        {
            num = (int)Mathf.Ceil((Convert.ToSingle(num) * 0.65f));
        }
    }
}
